//
//  NewsSearchResultCell.m
//  ShowYork
//
//  Created by hxh on 2021/5/14.
//  Copyright © 2021 hxh. All rights reserved.
//

#import "NewsSearchResultCell.h"

@interface NewsSearchResultCell ()
@property (nonatomic,strong)UILabel *titleLb;
@property (nonatomic,strong)UIView *line;
@property (nonatomic,strong)UIButton *coverBtn;
@end

@implementation NewsSearchResultCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.titleLb = [[UILabel alloc]init];
        self.titleLb.textColor = C51;
        self.titleLb.text = @"教育政策";
        self.titleLb.font = [UIFont boldSystemFontOfSize:14];
        [self.contentView addSubview:self.titleLb];
        
        self.line = [[UIView alloc]init];
        self.line.backgroundColor = C(230, 1);
        [self.contentView addSubview:self.line];
        [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-20);
            make.left.equalTo(self.contentView).offset(20);
            make.centerY.equalTo(self.contentView);
        }];
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(20);
            make.right.equalTo(self.contentView).offset(-18);
        }];
        
        self.coverBtn = [[UIButton alloc]init];
        [self.coverBtn addTarget:self action:@selector(coverMethod) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.coverBtn];
        [self.coverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.bottom.equalTo(self.contentView);
        }];
    }
    return self;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    NSString *ID = @"NewsSearchResultCell";
    NewsSearchResultCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[NewsSearchResultCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

- (void)setItemModel:(NewsListItemModel *)itemModel{
    _itemModel = itemModel;
    self.titleLb.text = itemModel.title;
}

- (void)coverMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(showNewsSearchResultByCurrentModel:)]) {
        [self.delegate showNewsSearchResultByCurrentModel:self.itemModel];
    }
}

@end
